package com.tang;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @author Tang
 * @classname sqlServerApp
 * @description [  ]
 * @date 2021/3/30 14:27
 */
@SpringBootApplication
public class SqlServerApp implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(SqlServerApp.class);
    }

    @Override
    public void run(String... args) throws Exception {
        System.out.println("执行数据库查询...start..");
        String url = "jdbc:sqlserver://192.168.228.194:1433;databaseName=HeatDataNew";
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        Connection connection = DriverManager.getConnection(url, "v4mis", "v4mis");
        String sql = "select * from V4MisEn where ttype = '供' or ttype = '用'";
        PreparedStatement statement = connection.prepareStatement(sql);
        ResultSet resultSet = statement.executeQuery();
        while (resultSet.next()) {
            System.out.println(
                    resultSet.getString("tname") +"--->"+ resultSet.getString("ttype")
            );
        }
        connection.close();
        System.out.println("执行数据库查询...end..");
    }
}